package cn.mjnxin.iot.gate;

import com.jfinal.kit.PathKit;
import com.jfinal.server.undertow.PropExt;
import com.jfinal.server.undertow.UndertowServer;

import cn.mjnxin.iot.base.log.LogWorker;
import io.jboot.app.JbootApplication;
import io.jboot.core.listener.JbootAppListenerBase;
import io.undertow.UndertowOptions;

/**
 * 网关启动入口
 * @author CLG 2023年10月10日
 * @version V1.0.0
 */
public class GateStart extends JbootAppListenerBase{

	private static String[] args;
	
    public static void main(String[] args) {
    	GateStart.args = args;
        PropExt undertowProp = (new PropExt()).append("jboot.properties");

        UndertowServer undertowServer = JbootApplication.createServer(args);

	    //提前设置webRootPath
	    String webRootPath = PathKit.getWebRootPath();
		JbootApplication.start(undertowServer.onStart(builder -> {
			builder.setServerOption(UndertowOptions.MAX_PARAMETERS, undertowProp.getInt("undertow.MAX_PARAMETERS", 1000));
			//最后设置undertow的资源路径
		    undertowServer.setResourcePath(webRootPath);
        }));
    }

    @Override
    public void onStartFinish() {
    	LogWorker.logForce("开始启动网关");
    	Gate.start(args);
    }
}
